﻿// -----------------------------------------------------------------------
// <copyright file="InfoDeLaQuery.cs" company="Hexacta S.A.">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace SQLVis.Entidades
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using gudusoft.gsqlparser;

    /// <summary>
    /// solo tiene la info de un row del slow query log
    /// # Time: 050718 19:45:58 
    /// # User@Host: db[db] @ localhost [127.0.0.1] 
    /// # Query_time: 3 Lock_time: 0 Rows_sent: 43 Rows_examined: 10310 
    /// </summary>
    public class InfoDeLaQuery
    {
        private string format = "MM/dd/yyyy HH:mm:ss";

        public DateTime Time{ get; set; }
        public string UserHost { get; set; }
        public int QueryTime{ get; set; }
        public int LockTime { get; set; }
        public int RowsSent { get; set; }
        public int RowsExamined { get; set; }
        public TCustomSqlStatement Query{ get; set; }
        public string QueryAsString { get { return Query.AsText; } }
        public string PatronAgrupamiento { get; set; }


        private char SeparadorDeLineas { get { return '&'; } }

        public override string ToString()
        {
            //string resultado = "# Time: " + Time.ToString(format) + System.Environment.NewLine +
            //                   "# User@Host: " + UserHost + System.Environment.NewLine +
            //                   "# Query_time: " + QueryTime + System.Environment.NewLine + 
            //                   " Lock_time: " + LockTime + System.Environment.NewLine +
            //                   "# Rows_sent: " + RowsSent + System.Environment.NewLine +
            //                   "# Rows_examined: " + RowsExamined + System.Environment.NewLine +
            //                   "Query: " + Query.RawSqlText;

            string resultado = "# Time: " + Time.ToString(format) + System.Environment.NewLine +
                               "# User@Host: " + UserHost + System.Environment.NewLine +
                               "# Query_time: " + QueryTime + " " +
                               " Lock_time: " + LockTime + " " +
                               " Rows_sent: " + RowsSent + " " +
                               " Rows_examined: " + RowsExamined + System.Environment.NewLine +
                               Query.AsText;
            return resultado;
        }


        public  string ToStringConsulta()
        {
            string resultado = "# Time: " + Time.ToString(format) + System.Environment.NewLine +
                               "# User@Host: " + UserHost + System.Environment.NewLine +
                               "# Query_time: " + QueryTime + System.Environment.NewLine +
                               " Lock_time: " + LockTime + System.Environment.NewLine +
                               " Rows_sent: " + RowsSent + System.Environment.NewLine +
                               " Rows_examined: " + RowsExamined + System.Environment.NewLine +
                               QueryAsString;
            return resultado;
        }

        public string[] toStringSeparadoEnLineas()
        {
            return this.ToString().Split(this.SeparadorDeLineas);
        }
    }
}
